package com.sdtbu.ylgh.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.sdtbu.ylgh.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.sdtbu.ylgh.entity.GhRosterEntity;
import com.sdtbu.ylgh.service.GhRosterService;



/**
 * 排班表
 *
 * @author mzd
 * @email 1695165447@qq.com
 * @date 2021-03-13 17:53:04
 */
@CrossOrigin
@RestController
@RequestMapping("ylgh/ghroster")
public class GhRosterController {
    @Autowired
    private GhRosterService ghRosterService;

    /**
     * 根据日期 和 门诊id 查询该门诊在该日期的排班表
     */
    @RequestMapping("/listday")
    public R list(Long time, String depId){
        System.out.println(new Date(time));
        System.out.println(depId);
        if (time == null){
            return R.error("时间错误");
        }
        if (time <= new Date().getTime()- 1000 * 60 * 60 * 24){
            time = new Date().getTime();
        }

        List<Map<String, Object>> mapList = ghRosterService.toDay(time, depId);

        return R.ok().put("rosterList", mapList);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("ylgh:ghroster:info")
    public R info(@PathVariable("id") Long id){
		GhRosterEntity ghRoster = ghRosterService.getById(id);

        return R.ok().put("ghRoster", ghRoster);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("ylgh:ghroster:save")
    public R save(@RequestBody GhRosterEntity ghRoster){
		ghRosterService.save(ghRoster);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("ylgh:ghroster:update")
    public R update(@RequestBody GhRosterEntity ghRoster){
		ghRosterService.updateById(ghRoster);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("ylgh:ghroster:delete")
    public R delete(@RequestBody Long[] ids){
		ghRosterService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
